package com.zc.designmodel.structural.criteria;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: zhuCan
 * @date: 2020/4/12 18:00
 * @description:
 */
public class OrCriteria implements Criteria {

  private Criteria criteria;
  private Criteria orCriteria;

  public OrCriteria(Criteria criteria,Criteria orCriteria){
    this.criteria=criteria;
    this.orCriteria=orCriteria;
  }

  @Override
  public List<Person> meetCriteria(List<Person> people) {
    List<Person> res=criteria.meetCriteria(people);
    List<Person> resOr=orCriteria.meetCriteria(people);
    List<Person> result=res.stream().filter(x->!resOr.contains(x)).collect(Collectors.toList());
    result.addAll(resOr);
    return result;
  }
}
